<?php
/**
 *
 *
 *
 */
namespace Yz\modules\News;

use Yz_SQL_Statement,
    StateError,
    Yz_String;

class Action_SelectByTitle
    extends Action_Select
{

    /**
     *  @var string
     */
    protected $title;

    /**
     *  @param int id > 0
     *  @return this
     */
    public function setTitle( $title )
    {
        debug();
        assert('is_string($title) and $title !== ""');
        $this->title = $title;
        // prevent the action instance from returning results after changing parameters
        $this->executed = false;
        return $this;
    }

    /************************************
     *        Protected methods         *
     ************************************/

    /** Verify arguments before building query
     *
     *  @return this
     */
    protected function verifyArguments()
    {
        debug();
        if (null === $this->title)
            throw StateError::_new_();
        return $this;
    }

    /**
     *  Build the common part of the SQL statement
     *  @abstract
     *  @return Yz_SQL_Statement
     */
    protected function buildStatement()
    {
        return parent::buildStatement()
            ->where( key($this->tables) . ".title=:_title")
        ;
    }

    /**
     *  Apply the arguments to the SQL statement
     *      Bind the id argument
     *  @param Yz_SQL_Statement $sql
     *  @return this
     */
    protected function applyArguments(Yz_SQL_Statement $sql)
    {
        debug();
        $sql
            ->bind("_title", $this->title)
        ;
        return $this;
    }


}
